<template>
  <div>
    <el-form
      :inline="true"
      :model="nickName"
      class="demo-form-inline"
      style="margin-top: 25px; margin-left: 30%"
    >
      <el-form-item label="用户昵称">
        <el-input v-model="nickName" placeholder="请输入用户昵称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          @click="loadCommentsByUserName(nickName, currentPage, limit)"
          >查询</el-button
        >
      </el-form-item>
    </el-form>
    <el-table :data="articleList" border style="width: 100%">
      <el-table-column
        prop="username"
        label="评论人昵称"
        width="100"
        align="center"
      >
      </el-table-column>
      <el-table-column label="评论帖子标题" width="300" align="center">
        <template slot-scope="scope">
          <P>
            {{ scope.row.title != null ? scope.row.title : "未知" }}
          </P>
        </template>
      </el-table-column>
      <el-table-column label="评论内容" width="300" align="center">
        <template slot-scope="scope">
          <P>
            {{ scope.row.content }}
          </P>
        </template>
      </el-table-column>
      <el-table-column
        prop="postTime"
        label="发布时间"
        width="200"
        align="center"
      >
      </el-table-column>
      <el-table-column prop="like" label="点赞量" width="200" align="center">
      </el-table-column>
      <el-table-column label="操作" width="250" align="center">
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="mini"
            icon="el-icon-more"
            @click="checkDetails(scope.row.content)"
            >详情</el-button
          >
          <el-button type="danger" size="mini" icon="el-icon-delete"
            >撤回</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :current-page="currentPage"
      :total="totalRecords"
      :page-size="limit"
      :page-sizes="[9, 18, 27, 36, 45, 54, 63]"
      style="margin: 30px 0; text-align: center"
      layout="sizes,prev,pager,next,jumper,->,total,slot"
      @current-change="getStudentList"
      @size-change="changeSize"
    />
  </div>
</template>

<script>
import adminControll from "@/api/adminControll";
export default {
  data() {
    return {
      nickName: "",
      currentPage: 1,
      limit: 9,
      totalRecords: 100,
      articleList: [
        {
          commentId: 10000,
          username: "测试账号",
          title: "第一个帖子，带图，带附件",
          content: "自己做沙发",
          postTime: "2023-01-16 02:01:35",
          like: 0,
        },
        {
          commentId: 10001,
          username: "测试账号",
          title: "第一个帖子，带图，带附件",
          content: "带图的评论",
          postTime: "2023-01-16 17:26:07",
          like: 1,
        },
        {
          commentId: 10002,
          username: "测试账号02",
          title: "第一个帖子，带图，带附件",
          content: "我来个评论",
          postTime: "2023-01-16 17:54:04",
          like: 0,
        },
        {
          commentId: 10003,
          username: "测试账号02",
          title: "第一个帖子，带图，带附件",
          content: "啦啦啦啦啦啦啦啦啦啦啦啦",
          postTime: "2023-01-16 22:40:53",
          like: 0,
        },
        {
          commentId: 10004,
          username: "李迈克",
          title: "第一个帖子，带图，带附件",
          content: "我坐沙发",
          postTime: "2023-02-04 05:50:46",
          like: 0,
        },
        {
          commentId: 10005,
          username: "苏曜",
          title: "第一个帖子，带图，带附件",
          content: "你好测试",
          postTime: "2023-02-03 22:03:58",
          like: 0,
        },
        {
          commentId: 10006,
          username: "李迈克",
          title: null,
          content: "string",
          postTime: "2023-02-13 20:56:15",
          like: 0,
        },
        {
          commentId: 10007,
          username: "苏曜",
          title: null,
          content: "string",
          postTime: "2023-02-13 20:57:45",
          like: 0,
        },
        {
          commentId: 10008,
          username: "Xzh",
          title: "第一个帖子，带图，带附件",
          content: "这篇文章真的棒",
          postTime: "2023-02-13 20:57:45",
          like: 1,
        },
      ],
    };
  },

  components: {},

  computed: {},

  created() {
    this.loadCommentsByUserName(this.nickName, this.currentPage, this.limit);
  },

  methods: {
    checkDetails(content) {
      this.$alert(content, "评论详情", {
        confirmButtonText: "取消",
      });
    },
    changeSize(size) {
      this.limit = size;
      this.getStudentList(1);
    },
    getStudentList(page = 1) {},
    loadCommentsByUserName(username, pageNo, pageSize) {
      adminControll
        .loadCommentsByUserName(username, pageNo, pageSize)
        .then((response) => {
          if (response.data == null) {
            this.articleList = [];
            this.totalRecords = 0;
          } else {
            this.articleList = [];
            for (var i = 0; i < response.data.records.length; i++) {
              var article = response.data.records[i];
              if (article.title != null) {
                this.articleList.push(article);
              }
            }
            this.totalRecords = response.data.total;
          }
        });
    },
  },
};
</script>
<style scoped>
img {
  display: block;
  width: 75px;
  height: 75px;
}
.exceed {
  color: red;
}
p {
  width: 250px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
</style>
